package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import com.itheima.pojo.WebConfig;
import com.itheima.service.WebConfigService;
import com.itheima.utils.MessageConstant;
import com.itheima.utils.ResultUtil;
import com.itheima.vo.SysDictTypeVO;
import com.itheima.vo.WebConfigVO;
import com.netflix.ribbon.proxy.annotation.Http;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/*
* 网站配置
* */

@RestController
@RequestMapping("/webConfig")
@CrossOrigin
public class WebConfigController {

    @Autowired
    private WebConfigService webConfigService;

    /**
     * 修改网站配置
     *@param webConfigVO
     * @return com.itheima.entity.Result
     *@author itheima
     */
    @PostMapping("/editWebConfig")
    public String editWebConfig(@RequestBody WebConfigVO webConfigVO) {
        int count = webConfigService.edit(webConfigVO);
        if (count > 0) {
            return ResultUtil.result(HttpServletResponse.SC_OK, MessageConstant.WEBCONFIG_EDIG_SUCCESS);
        } else {
            return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED,MessageConstant.WEBCONFIG_EDIG_FAIL);
        }
    }

    /**
     * 获取网站配置
     *@param
     * @return java.lang.String
     *@author itheima
     */
    @GetMapping("/getWebConfig")
    public String getWebConfig() {
        List<WebConfig> webConfigList = null;
        try {
            webConfigList = webConfigService.getWebConfig();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED,MessageConstant.WEBCONFIG_SELECT_FAIL);
        }
        return ResultUtil.result(HttpServletResponse.SC_OK,webConfigList);
    }

}
